/******************************************************************************/
/** Common Javascript functions                                              **/
/******************************************************************************/
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/******************************************************************************/
/** Common Jquery function                                                   **/
/******************************************************************************/
function show_ID_PWD_Form(formType){
    // remove all class on, hidden forms
    $('#idpwd_form div.icon').removeClass('on');
    $('#idpwd_form div.form').hide();
    
    // add class on to current element
    $('#idpwd_form div.'+ formType).addClass('on');
    
    // show input form
    $('#idpwd_form #form_'+ formType).show();
}
function show_Review_Item(itemID){
    // find review content by ID
    var $tableRow = $('#'+ itemID);
    
    // hide all table row even
    // $('#table_review > tbody > tr:odd').hide();
    
    // if table hide then show and else
    $tableRow.toggle();
}
function show_QnA_Item(itemID){
    // find QnA content by ID
    var $tableRow = $('#'+ itemID);
    
    // hide all table row even
    // $('#table_qna > tbody > tr:odd').hide();
    
    // if table hide then show and else
    $tableRow.toggle();
}
function show_BaBo_Popup(elemID, isCenter){
    // get current modal poup
    var $modal = $('#'+ elemID);
    
    // create div overlay
    var $overlay = $('<div class="overlay"></div>');
    
    // remove all overlay, insert before modal
    $overlay.remove().insertBefore($modal);
    
    // calculator width, height, center screen
    var $window = $(window);
    if(isCenter === true){
        $modal.css({
            'position' : 'absolute',
            'top' : Math.abs((($window.height() - $modal.outerHeight()) / 2) + $window.scrollTop()),
            'left' : Math.abs((($window.width() - $modal.outerWidth()) / 2) + $window.scrollLeft())
        });
    }
    
    // show modal popup
    $modal.show();
    
    // bind event when overlay click
    $overlay.click(function(){
        $(this).remove();
        $modal.fadeOut();
    });
    
    // bind close event button
    $modal.children('.close').click(function(){
        $overlay.remove();
        $modal.fadeOut();
    });
}
function hide_BaBo_Popup(elemID){
    // get current modal poup
    var $modal = $('#'+ elemID);
    
    // hide modal popup
    $modal.fadeOut();
}
function show_Babo_Review(menuID, reviewID){
    // get element 
    var $menuElem   = $('#'+ menuID);
    var $reviewElem = $('#'+ reviewID);
    
    // remove all on class inner menu
    $menuElem.parents('ul').children('li').children('a').removeClass('on');
    
    // all on class for menu
    $menuElem.addClass('on');
    
    // hiden all child div in parent container
    $reviewElem.parent('div').children('div').hide();

    // show current div
    $reviewElem.show();
}
function show_Option_Price(selectID, divWrapperID, divTotalID){
    var $optionElem     = $('#'+ selectID + ' option:selected');
    var $divWrapperElem = $('#'+ divWrapperID);
    var $divTotalElem   = $('#'+ divTotalID);
    
    // declare var
    var htmlItem  = '';
    var htmlTotal = '';
    
    // get, caculator
    var optName  = $optionElem.text();
    var optPrice = $optionElem.val();
    
    // build html option price
    htmlItem += '<div class="item">';
    htmlItem += '  <table>';
    htmlItem += '      <tr>';
    htmlItem += '          <td class="nm">'+ optName +'</td>';
    htmlItem += '          <td class="num">';
    htmlItem += '              <ul class="boxqty">';
    htmlItem += '                  <li class="decrease"><span></span></li>';
    htmlItem += '                  <li class="text"><input type="text" name="" value="1" /></li>';
    htmlItem += '                  <li class="increase"><span></span></li>';
    htmlItem += '              </ul>';
    htmlItem += '          </td>';
    htmlItem += '          <td class="pr">';
    htmlItem += '              <span class="price">'+ optPrice +'</span><a href="#"><img class="close" src="img/product/btn_box_close.gif" /></a>';
    htmlItem += '          </td>';
    htmlItem += '      </tr>';
    htmlItem += '  </table>';
    htmlItem += '</div>';
    
    // build html total
    htmlTotal += ' <div class="item">';
    htmlTotal += '     <table>';
    htmlTotal += '         <tr>';
    htmlTotal += '             <td class="nm all">합계금액</td>';
    htmlTotal += '             <td class="pr all"><span class="fr total">25,600</span></td>';
    htmlTotal += '         </tr>';
    htmlTotal += '     </table>';
    htmlTotal += ' </div>';
    
    // show option price if div wrapper not contains option name 
    // and selected option has price value
    if($('#'+ divWrapperID +':contains("'+ optName +'")').length === 0 
        && $optionElem.val() !== ''){
        $divWrapperElem.append(htmlItem);
    }
    
    // show total price
    $divTotalElem.empty().html(htmlTotal);
}